/*
========================================================================
 Name        : CallDetailTrackerMainFormView.cpp
 Author      : 
 Copyright   : Your copyright notice
 Description : 
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <aknviewappui.h>
#include <eikmenub.h>
#include <avkon.hrh>
#include <akncontext.h>
#include <akntitle.h>
#include <stringloader.h>
#include <barsread.h>
#include <eikbtgpc.h>
#include <aknquerydialog.h>
#include <CallDetailTracker.rsg>
// ]]] end generated region [Generated System Includes]

// [[[ begin generated region: do not modify [Generated User Includes]

#include "CallDetailTracker.hrh"
#include "CallDetailTrackerMainFormView.h"
#include "CallDetailTrackerMainForm.hrh"
#include "CallDetailTrackerViewReportOptionsForm.hrh"
#include "CallDetailTrackerGenerateReportForm.hrh"
#include "CallDetailTrackerProgressingForm.hrh"
#include "CallDetailTrackerMainForm.h"
// ]]] end generated region [Generated User Includes]

#include "FileManager.h"

// [[[ begin generated region: do not modify [Generated Constants]
// ]]] end generated region [Generated Constants]


FileManager* fileMgr=new FileManager() ;
	
/**
 * First phase of Symbian two-phase construction. Should not contain any
 * code that could leave.
 */
CCallDetailTrackerMainFormView::CCallDetailTrackerMainFormView()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	iCallDetailTrackerMainForm = NULL;
	// ]]] end generated region [Generated Contents]
	
	// [[[ begin generated region: do not modify [Generated Contents]
	// ]]] end generated region [Generated Contents]
	
	}

/** 
 * The view's destructor removes the container from the control
 * stack and destroys it.
 */
CCallDetailTrackerMainFormView::~CCallDetailTrackerMainFormView()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	delete iCallDetailTrackerMainForm;
	iCallDetailTrackerMainForm = NULL;
	// ]]] end generated region [Generated Contents]
	
	// [[[ begin generated region: do not modify [Generated Contents]
	// ]]] end generated region [Generated Contents]
	
	}

/**
 * Symbian two-phase constructor.
 * This creates an instance then calls the second-phase constructor
 * without leaving the instance on the cleanup stack.
 * @return new instance of CCallDetailTrackerMainFormView
 */
CCallDetailTrackerMainFormView* CCallDetailTrackerMainFormView::NewL()
	{
	CCallDetailTrackerMainFormView* self = CCallDetailTrackerMainFormView::NewLC();
	CleanupStack::Pop( self );
	return self;
	}

/**
 * Symbian two-phase constructor.
 * This creates an instance, pushes it on the cleanup stack,
 * then calls the second-phase constructor.
 * @return new instance of CCallDetailTrackerMainFormView
 */
CCallDetailTrackerMainFormView* CCallDetailTrackerMainFormView::NewLC()
	{
	CCallDetailTrackerMainFormView* self = new ( ELeave ) CCallDetailTrackerMainFormView();
	CleanupStack::PushL( self );
	self->ConstructL();
	return self;
	}


/**
 * Second-phase constructor for view.  
 * Initialize contents from resource.
 */ 
void CCallDetailTrackerMainFormView::ConstructL()
	{
	// [[[ begin generated region: do not modify [Generated Code]
	BaseConstructL( R_CALL_DETAIL_TRACKER_MAIN_FORM_CALL_DETAIL_TRACKER_MAIN_FORM_VIEW );
				
	// ]]] end generated region [Generated Code]
	
	// add your own initialization code here
	
	// [[[ begin generated region: do not modify [Generated Code]
	// ]]] end generated region [Generated Code]
	
	}

/**
 * @return The UID for this view
 */
TUid CCallDetailTrackerMainFormView::Id() const
	{
	return TUid::Uid( ECallDetailTrackerMainFormViewId );
	}

/**
 * Handle a command for this view (override)
 * @param aCommand command id to be handled
 */
void CCallDetailTrackerMainFormView::HandleCommandL( TInt aCommand )
	{	
	// [[[ begin generated region: do not modify [Generated Code]
	TBool commandHandled = EFalse;
	switch ( aCommand )
		{	// code to dispatch to the AknView's menu and CBA commands is generated here
	
		case EAknSoftkeyExit:
			commandHandled = HandleControlPaneRightSoftKeyPressedL( aCommand );
			break;
		case ECallDetailTrackerMainFormViewGenerate_ReportMenuItemCommand:
			commandHandled = HandleGenerate_ReportMenuItemSelectedL( aCommand );
			break;
		case ECallDetailTrackerMainFormViewView_Last_Generated_ReportMenuItemCommand:
			commandHandled = HandleView_Last_Generated_ReportMenuItemSelectedL( aCommand );
			break;
		case ECallDetailTrackerMainFormViewDeleteCallLogMenuItemCommand:
			commandHandled = HandleDeleteCallLogMenuItemSelectedL( aCommand );
			break;
		case ECallDetailTrackerMainFormViewExitMenuItem1Command:
			commandHandled = HandleExitMenuItem1SelectedL( aCommand );
			break;
		default:
			break;
		}
	
		
	if ( !commandHandled ) 
		{
	
		if ( aCommand == EAknSoftkeyExit )
			{
			AppUi()->HandleCommandL( EEikCmdExit );
			}
	
		}
	// ]]] end generated region [Generated Code]
	
	// Exit function in the options menu. 
	if ( aCommand == ECallDetailTrackerMainFormViewExitMenuItem1Command )
	{
		AppUi()->HandleCommandL( EEikCmdExit );
	}

	
	// [[[ begin generated region: do not modify [Generated Code]
	// ]]] end generated region [Generated Code]
	
	}

/**
 *	Handles user actions during activation of the view, 
 *	such as initializing the content.
 */
void CCallDetailTrackerMainFormView::DoActivateL( 
		const TVwsViewId& /*aPrevViewId*/,
		TUid /*aCustomMessageId*/,
		const TDesC8& /*aCustomMessage*/ )
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	SetupStatusPaneL();
	
				
	if ( iCallDetailTrackerMainForm == NULL )
		{
		iCallDetailTrackerMainForm = CreateContainerL();
		iCallDetailTrackerMainForm->SetMopParent( this );
		AppUi()->AddToStackL( *this, iCallDetailTrackerMainForm );
		} 
	// ]]] end generated region [Generated Contents]
	
	// [[[ begin generated region: do not modify [Generated Contents]
	// ]]] end generated region [Generated Contents]
	
	}

/**
 */
void CCallDetailTrackerMainFormView::DoDeactivate()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	CleanupStatusPane();
	
	if ( iCallDetailTrackerMainForm != NULL )
		{
		AppUi()->RemoveFromViewStack( *this, iCallDetailTrackerMainForm );
		delete iCallDetailTrackerMainForm;
		iCallDetailTrackerMainForm = NULL;
		}
	// ]]] end generated region [Generated Contents]
	
	// [[[ begin generated region: do not modify [Generated Contents]
	// ]]] end generated region [Generated Contents]
	
	}

/** 
 * Handle status pane size change for this view (override)
 */
void CCallDetailTrackerMainFormView::HandleStatusPaneSizeChange()
	{
	CAknView::HandleStatusPaneSizeChange();
	
	// this may fail, but we're not able to propagate exceptions here
	TVwsViewId view;
	AppUi()->GetActiveViewId( view );
	if ( view.iViewUid == Id() )
		{
		TInt result;
		TRAP( result, SetupStatusPaneL() );
		}
	
	// [[[ begin generated region: do not modify [Generated Code]
	// ]]] end generated region [Generated Code]
	
	}

// [[[ begin generated function: do not modify
void CCallDetailTrackerMainFormView::SetupStatusPaneL()
	{
	// reset the context pane
	TUid contextPaneUid = TUid::Uid( EEikStatusPaneUidContext );
	CEikStatusPaneBase::TPaneCapabilities subPaneContext = 
		StatusPane()->PaneCapabilities( contextPaneUid );
	if ( subPaneContext.IsPresent() && subPaneContext.IsAppOwned() )
		{
		CAknContextPane* context = static_cast< CAknContextPane* > ( 
			StatusPane()->ControlL( contextPaneUid ) );
		context->SetPictureToDefaultL();
		}
	
	// setup the title pane
	TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
	CEikStatusPaneBase::TPaneCapabilities subPaneTitle = 
		StatusPane()->PaneCapabilities( titlePaneUid );
	if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
		{
		CAknTitlePane* title = static_cast< CAknTitlePane* >( 
			StatusPane()->ControlL( titlePaneUid ) );
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_CALL_DETAIL_TRACKER_MAIN_FORM_TITLE_RESOURCE );
		title->SetFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
				
	}
















void CCallDetailTrackerMainFormView::CleanupStatusPane()
	{
	}
















CCallDetailTrackerMainForm* CCallDetailTrackerMainFormView::CreateContainerL()
	{
	return CCallDetailTrackerMainForm::NewL( ClientRect(), NULL, this );
	}

// [[[ begin generated function: do not modify
/**
 * Show the popup dialog for exitQuery
 * @param aOverrideText optional override text
 * @return EAknSoftkeyYes (left soft key id) or 0
 */
TInt CCallDetailTrackerMainFormView::RunExitQueryL( const TDesC* aOverrideText )
	{
				
	CAknQueryDialog* queryDialog = CAknQueryDialog::NewL();	
	
	if ( aOverrideText != NULL )
		{
		queryDialog->SetPromptL( *aOverrideText );
		}
	return queryDialog->ExecuteLD( R_CALL_DETAIL_TRACKER_MAIN_FORM_EXIT_QUERY );
	}
/** 
 * Handle the rightSoftKeyPressed event.
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CCallDetailTrackerMainFormView::HandleControlPaneRightSoftKeyPressedL( TInt aCommand )
	{
	// showing the Exit Query
		TInt response = this->RunExitQueryL();
		
		if(response != 0){	// selected to exit
			
			// send the application to background	
			TApaTask task(iEikonEnv->WsSession());
			task.SetWgId( CEikonEnv::Static()->RootWin().Identifier());
			task.SendToBackground();
		
			return ETrue;	// if this is set to EFalse or not mentioned, then a new app is created when it is loaded again.
		}
		else{				// selected not to exit
			return ETrue;
		}
	}
				
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CCallDetailTrackerMainFormView::HandleGenerate_ReportMenuItemSelectedL( TInt aCommand )
	{
	static_cast<CAknViewAppUi*>(CEikonEnv::Static()->AppUi())->ActivateLocalViewL( TUid::Uid( ECallDetailTrackerGenerateReportFormViewId ) );
	return ETrue;
	}
				
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CCallDetailTrackerMainFormView::HandleView_Last_Generated_ReportMenuItemSelectedL( TInt aCommand )
	{
	FileManager* iFile2;
    iFile2 = new(ELeave) FileManager;
    iFile2->openFile();
	return ETrue;
	}					
				
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CCallDetailTrackerMainFormView::HandleDeleteCallLogMenuItemSelectedL( TInt aCommand )
	{
	static_cast<CAknViewAppUi*>(CEikonEnv::Static()->AppUi())->ActivateLocalViewL( TUid::Uid( ECallDetailTrackerDeleteCallLogSelectorViewId ) );
		return ETrue;
	}
	
/** 
 * Handle the selected event.
 * @param aCommand the command id invoked
 * @return ETrue if the command was handled, EFalse if not
 */
TBool CCallDetailTrackerMainFormView::HandleExitMenuItem1SelectedL( TInt aCommand )
	{
	//AppUi()->HandleCommandL( EEikCmdExit );
	return ETrue;
	}
